//
//  JSMMyViewController.m
//  TakeYouTourTogether
//
//  Created by king on 15/11/26.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMMyViewController.h"
#import "JSMFeedBackViewController.h"
#import "JSMMoreViewController.h"
#import "JSMNewSaveViewController.h"
#import "JSMNewSaveViewController.h"
#import "JSMSettingCell.h"
@interface JSMMyViewController ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, strong)BaseTableView* myTableView;
@property(nonatomic, strong)BaseImageView *imageView;
@property(nonatomic, strong)NSArray *titleArr;
@property(nonatomic, strong)NSArray *imageArr;
@end

@implementation JSMMyViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.titleArr = @[@"我的关注", @"清除缓存", @"意见反馈", @"更多设置"];
        self.imageArr = @[@"guanzhu.png", @"qingchuhuancun.png", @"yijianfankui", @"shezhi"];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:0.95];
    [self createView];

}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.title = LanguageTool(@"我");
    [self.myTableView reloadData];
}
- (void)changeColor:(NSNotification *)notification{
    [super changeColor:notification];
    self.imageView.image = [UIImage imageNamed:notification.userInfo[@"name"]];
    
}

#pragma mark - createTableView
- (void)createView{
    self.myTableView = [[BaseTableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    [self.view addSubview:self.myTableView];
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.myTableView.bounces = NO;
    self.imageView = [[BaseImageView alloc]initWithFrame:CGRectMake(0, 0, VIEWWIDTH, 200* ALL_EDITION_HEIGHT)];
    self.imageView.image = [UIImage imageNamed:@"back1111"];
    self.myTableView.tableHeaderView = self.imageView;
    
    
}
#pragma mark tableView协议方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.titleArr.count;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *str = @"reuse";
    JSMSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    if (!cell) {
        cell = [[JSMSettingCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    if (indexPath.section == 1) {
        BaseLabel *lanLabel = [[BaseLabel alloc]initWithFrame:CGRectMake(0, 0, 60, 40)];
        cell.accessoryView = lanLabel;
        lanLabel.font = [UIFont systemFontOfSize:13];
        lanLabel.textColor = [UIColor lightGrayColor];
        lanLabel.text = [CacheOrClearCache howManyCache];
        lanLabel.textAlignment = NSTextAlignmentRight;
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.imageView.image = [UIImage imageNamed:self.imageArr[indexPath.section]];
    cell.settingLabel.text = LanguageTool(self.titleArr[indexPath.section]);
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    BaseLabel *headerLabel = [[BaseLabel alloc]initWithFrame:CGRectMake(0, 0, VIEWWIDTH, 15)];
    headerLabel.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
    return headerLabel;
    
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        JSMNewSaveViewController *saveVC = [[JSMNewSaveViewController alloc]init];
        saveVC.navigationItem.hidesBackButton = YES;
        [self.navigationController pushViewController:saveVC animated:YES];

    }else if (indexPath.section == 1) {
        //清除缓存
        [CacheOrClearCache clearCache];
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:LanguageTool(@"清除缓存")  message:LanguageTool(@"缓存已清除") preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alertController animated:YES completion:^{
        }];
        [self dismissViewControllerAnimated:alertController completion:^{
        }];
        [self.myTableView reloadData];
    }else if (indexPath.section == 2) {
        //用户反馈
        JSMFeedBackViewController *feedBackVC = [[JSMFeedBackViewController alloc]init];
        feedBackVC.navigationItem.hidesBackButton = YES;
        [self.navigationController pushViewController:feedBackVC animated:YES];
    }else if (indexPath.section == 3) {
        //更多设置
        JSMMoreViewController *moreVC = [[JSMMoreViewController alloc]init];
        moreVC.navigationItem.hidesBackButton = YES;
        [self.navigationController pushViewController:moreVC animated:YES];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
